<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActiveScaffold::DataStructures::Sorting</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActiveScaffold::DataStructures::Sorting</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/plugins/active_scaffold/lib/data_structures/sorting_rb.html">
                vendor/plugins/active_scaffold/lib/data_structures/sorting.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
encapsulates the column sorting configuration for the List view
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000442">&lt;&lt;</a>&nbsp;&nbsp;
      <a href="#M000441">add</a>&nbsp;&nbsp;
      <a href="#M000444">clear</a>&nbsp;&nbsp;
      <a href="#M000446">direction_of</a>&nbsp;&nbsp;
      <a href="#M000449">each</a>&nbsp;&nbsp;
      <a href="#M000450">first</a>&nbsp;&nbsp;
      <a href="#M000451">get_clause</a>&nbsp;&nbsp;
      <a href="#M000452">get_column</a>&nbsp;&nbsp;
      <a href="#M000453">mixed_sorting?</a>&nbsp;&nbsp;
      <a href="#M000440">new</a>&nbsp;&nbsp;
      <a href="#M000443">set</a>&nbsp;&nbsp;
      <a href="#M000447">sorts_by_method?</a>&nbsp;&nbsp;
      <a href="#M000448">sorts_by_sql?</a>&nbsp;&nbsp;
      <a href="#M000445">sorts_on?</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name">Enumerable</span>
      </div>
    </div>

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000440" class="method-detail">
        <a name="M000440"></a>

        <div class="method-heading">
          <a href="#M000440" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(columns)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000440-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000440-source">
<pre>
   <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/data_structures/sorting.rb, line 6</span>
6:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">columns</span>)
7:       <span class="ruby-ivar">@columns</span> = <span class="ruby-identifier">columns</span>
8:       <span class="ruby-ivar">@clauses</span> = []
9:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000442" class="method-detail">
        <a name="M000442"></a>

        <div class="method-heading">
          <a href="#M000442" class="method-signature">
          <span class="method-name">&lt;&lt;</span><span class="method-args">(arg)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
an alias for <tt><a href="Sorting.html#M000441">add</a></tt>. must accept
its arguments in a slightly different form, though.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000442-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000442-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/data_structures/sorting.rb, line 23</span>
23:     <span class="ruby-keyword kw">def</span> <span class="ruby-operator">&lt;&lt;</span>(<span class="ruby-identifier">arg</span>)
24:       <span class="ruby-identifier">add</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">arg</span>)
25:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000441" class="method-detail">
        <a name="M000441"></a>

        <div class="method-heading">
          <a href="#M000441" class="method-signature">
          <span class="method-name">add</span><span class="method-args">(column_name, direction = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
<a href="Sorting.html#M000441">add</a> a clause to the sorting, assuming
the column is sortable
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000441-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000441-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/data_structures/sorting.rb, line 12</span>
12:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add</span>(<span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">direction</span> = <span class="ruby-keyword kw">nil</span>)
13:       <span class="ruby-identifier">direction</span> <span class="ruby-operator">||=</span> <span class="ruby-value str">'ASC'</span>
14:       <span class="ruby-identifier">direction</span> = <span class="ruby-identifier">direction</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">upcase</span>
15:       <span class="ruby-identifier">column</span> = <span class="ruby-identifier">get_column</span>(<span class="ruby-identifier">column_name</span>)
16:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Could not find column #{column_name}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">nil?</span>
17:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;Sorting direction unknown&quot;</span> <span class="ruby-keyword kw">unless</span> [<span class="ruby-identifier">:ASC</span>, <span class="ruby-identifier">:DESC</span>].<span class="ruby-identifier">include?</span> <span class="ruby-identifier">direction</span>.<span class="ruby-identifier">to_sym</span>
18:       <span class="ruby-ivar">@clauses</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-identifier">column</span>, <span class="ruby-identifier">direction</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">sortable?</span>
19:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;Can't mix :method- and :sql-based sorting&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">mixed_sorting?</span>
20:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000444" class="method-detail">
        <a name="M000444"></a>

        <div class="method-heading">
          <a href="#M000444" class="method-signature">
          <span class="method-name">clear</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
clears the sorting
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000444-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000444-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/data_structures/sorting.rb, line 34</span>
34:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear</span>
35:       <span class="ruby-ivar">@clauses</span> = []
36:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000446" class="method-detail">
        <a name="M000446"></a>

        <div class="method-heading">
          <a href="#M000446" class="method-signature">
          <span class="method-name">direction_of</span><span class="method-args">(column)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000446-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000446-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/data_structures/sorting.rb, line 43</span>
43:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">direction_of</span>(<span class="ruby-identifier">column</span>)
44:       <span class="ruby-identifier">clause</span> = <span class="ruby-identifier">get_clause</span>(<span class="ruby-identifier">column</span>)
45:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">clause</span>.<span class="ruby-identifier">nil?</span>
46:       <span class="ruby-identifier">clause</span>[<span class="ruby-value">1</span>]
47:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000449" class="method-detail">
        <a name="M000449"></a>

        <div class="method-heading">
          <a href="#M000449" class="method-signature">
          <span class="method-name">each</span><span class="method-args">() {|clause| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
iterate over the clauses
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000449-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000449-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/data_structures/sorting.rb, line 59</span>
59:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each</span>
60:       <span class="ruby-ivar">@clauses</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">clause</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">clause</span> }
61:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000450" class="method-detail">
        <a name="M000450"></a>

        <div class="method-heading">
          <a href="#M000450" class="method-signature">
          <span class="method-name">first</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
provides quick access to the <a href="Sorting.html#M000450">first</a> (and
sometimes only) clause
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000450-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000450-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/data_structures/sorting.rb, line 64</span>
64:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">first</span>
65:       <span class="ruby-ivar">@clauses</span>.<span class="ruby-identifier">first</span>
66:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000443" class="method-detail">
        <a name="M000443"></a>

        <div class="method-heading">
          <a href="#M000443" class="method-signature">
          <span class="method-name">set</span><span class="method-args">(*args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
clears the sorting before setting to the given column/direction
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000443-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000443-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/data_structures/sorting.rb, line 28</span>
28:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
29:       <span class="ruby-identifier">clear</span>
30:       <span class="ruby-identifier">add</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
31:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000447" class="method-detail">
        <a name="M000447"></a>

        <div class="method-heading">
          <a href="#M000447" class="method-signature">
          <span class="method-name">sorts_by_method?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
checks whether any column is configured to sort by method (using a proc)
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000447-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000447-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/data_structures/sorting.rb, line 50</span>
50:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sorts_by_method?</span>
51:       <span class="ruby-ivar">@clauses</span>.<span class="ruby-identifier">any?</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">sorting</span><span class="ruby-operator">|</span> <span class="ruby-identifier">sorting</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Hash</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">sorting</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">:method</span> }
52:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000448" class="method-detail">
        <a name="M000448"></a>

        <div class="method-heading">
          <a href="#M000448" class="method-signature">
          <span class="method-name">sorts_by_sql?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000448-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000448-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/data_structures/sorting.rb, line 54</span>
54:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sorts_by_sql?</span>
55:       <span class="ruby-ivar">@clauses</span>.<span class="ruby-identifier">any?</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">sorting</span><span class="ruby-operator">|</span> <span class="ruby-identifier">sorting</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Hash</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">sorting</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">:sql</span> }
56:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000445" class="method-detail">
        <a name="M000445"></a>

        <div class="method-heading">
          <a href="#M000445" class="method-signature">
          <span class="method-name">sorts_on?</span><span class="method-args">(column)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
checks whether the given column (a <a href="Column.html">Column</a> object
or a column name) is in the sorting
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000445-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000445-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/data_structures/sorting.rb, line 39</span>
39:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sorts_on?</span>(<span class="ruby-identifier">column</span>)
40:       <span class="ruby-operator">!</span><span class="ruby-identifier">get_clause</span>(<span class="ruby-identifier">column</span>).<span class="ruby-identifier">nil?</span>
41:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M000451" class="method-detail">
        <a name="M000451"></a>

        <div class="method-heading">
          <a href="#M000451" class="method-signature">
          <span class="method-name">get_clause</span><span class="method-args">(column)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
retrieves the sorting clause for the given column
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000451-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000451-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/data_structures/sorting.rb, line 71</span>
71:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_clause</span>(<span class="ruby-identifier">column</span>)
72:       <span class="ruby-identifier">column</span> = <span class="ruby-identifier">get_column</span>(<span class="ruby-identifier">column</span>)
73:       <span class="ruby-ivar">@clauses</span>.<span class="ruby-identifier">find</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">clause</span><span class="ruby-operator">|</span> <span class="ruby-identifier">clause</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">column</span>}
74:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000452" class="method-detail">
        <a name="M000452"></a>

        <div class="method-heading">
          <a href="#M000452" class="method-signature">
          <span class="method-name">get_column</span><span class="method-args">(name_or_column)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
possibly converts the given argument into a column object from @columns (if
it&#8216;s not already)
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000452-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000452-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/data_structures/sorting.rb, line 77</span>
77:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_column</span>(<span class="ruby-identifier">name_or_column</span>)
78:       <span class="ruby-comment cmt"># it's a column</span>
79:       <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">name_or_column</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">name_or_column</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">DataStructures</span><span class="ruby-operator">::</span><span class="ruby-constant">Column</span>
80:       <span class="ruby-comment cmt"># it's a name</span>
81:       <span class="ruby-identifier">name_or_column</span> = <span class="ruby-identifier">name_or_column</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'.'</span>).<span class="ruby-identifier">last</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">name_or_column</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value str">'.'</span>
82:       <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@columns</span>[<span class="ruby-identifier">name_or_column</span>]
83:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000453" class="method-detail">
        <a name="M000453"></a>

        <div class="method-heading">
          <a href="#M000453" class="method-signature">
          <span class="method-name">mixed_sorting?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000453-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000453-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/data_structures/sorting.rb, line 85</span>
85:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mixed_sorting?</span>
86:       <span class="ruby-identifier">sorts_by_method?</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">sorts_by_sql?</span>
87:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>